<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{$tpshop_config['shop_info_store_title']}</title>
<meta http-equiv="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
<meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
<script src="__PUBLIC__/js/jquery-1.8.2.min.js"></script>
<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/js/pc_common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>

</head>

<body>
<include file="Public/header" />

    <div class="breadcrumb-area">    
<div class="layout">
	  
           <img src="__STATIC__/images/cart_btn.jpg" >我的購物車
       
    </div>
</div>
<link rel="stylesheet" href="__STATIC__/css/cart.css" type="text/css">
<style>
	/*.address tr td { border:#F00 solid 1px; }*/
    /*没选中的 收货地址*/
    .order-address-list table{background-color:inherit; border: 0px solid #CCC;}
    .order-address-list .default{visibility:hidden;}
    /*选中的 收货地址*/	
    .address_current{ background-color:#FAFAFA;} 
	.address_current .default{visibility:visible;}			
</style>
<form name="cart2_form" id="cart2_form" method="post">
    <div class="layout be-table fo-fa ma-bo-45">
    	<div class="con-info">
        	<div class="con-y-info ma-bo-35">
            	<h3 style="margin-top:30px">收货人信息<b>[<a href="javascript:void(0);" onClick="add_edit_address(0);">使用新地址</a>]</b></h3>
                <div id="ajax_address"><!--ajax 返回收货地址--></div>
               <!--  <h3 style="margin-top:30px">自提点</h3>
                <div id="ajax_pickup"></div> -->
            </div>
        	<div class="con-y-info ma-bo-35 con-h">
            	<h3>发票信息<em>(请谨慎选择发票抬头，订单出库后不能修改)</em></h3>
                <div class="order-invoice-list">
            		<ul>
            		<li>
                    	<div class="invoice-main fl"><label for="dw">发票抬头:</label></div>
                        <div class="invoice-sub fl">
                        	<label class="inv-label">
                        		<input class="officdw" type="text" name="invoice_title" placeholder="XXX单位 或 XX个人" />
                            </label>
                        </div>
                    </li>
            	</ul>
            	</div>
            </div>
			<div class="con-y-info ma-bo-35 con-h">
            	<h3>物流信息<em>(选择相应的物流配送，订单出库后不能修改)</em></h3>
                <div class="order-invoice-list">
            		<ul>
                    <foreach name="shippingList" item="v"  key="k">
                        <li>
                            <div class="invoice-main">
                                <input id="{$v.code}" type="radio" name="shipping_code" value="{$v.code}" onClick="ajax_order_price();" <if condition="$k eq 0"> checked="checked" </if> />
                                <label for="gr">{$v.name}</label>
                            </div>
                        </li>
            		</foreach>
	            	</ul>
            	</div>
            </div>            
        </div>
		<div class="con-y-info ma-bo-35 con-h">
            	<h3>您購買的以下商品</h3>
		</div>
        <div class="sc-area">
        	<div class="dt-order-area">
            	<div class="order-pro-list">
                	<div class="order-pro-list">
                    	<div class="yxspy">
                        	<div class="bv">
                            	<table border="0" cellpadding="0" cellspacing="0">
                                    <thead>
                                        <tr>
                                            <th class="tr-pro" style="text-align:left;">商品名稱</th>
                                            <th class="tr-price">單價（元）</th>
                                            <if condition="($user[discount] neq 1)">
                                            	<th class="tr-price" style="display:none;">会员折扣价</th>
                                            </if>
                                            <th class="tr-quantity">購買數量</th>
                                            <th class="tr-subtotal">應付（元）</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                        <div class="leiliste">
                        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
                                <tbody>
                                <foreach name="cartList" item="v"  key="k">
                                 <if condition="$v[selected] eq '1'">
                                    <tr>
                                        <td class="tr-pro">
                                            <ul class="pro-area-2"  style="padding-left:0;">
                                                <li>
                                                  <a title="{$v.goods_name}" target="_blank" href="{:U('Home/Goods/goodsInfo',array('id'=>$v[goods_id]))}" seed="item-name">{$v.goods_name}</a>
                                                </li> 
                                             </ul>
                                         </td>
                                        <!-- 预付订金商品的价格为空 -->
                                        <td class="tr-price te-al">¥{$v.goods_price}</td>
                                        <if condition="($user[discount] neq 1)">
                                        	<td class="tr-price te-al"  style="display:none;">¥{$v.member_goods_price}</td>
                                        </if>
                                        <td class="tr-quantity te-al">{$v.goods_num}</td>
                                        <td rowspan="1" class="tr-subtotal te-al">
                                        <p><b>￥{$v.goods_fee}</b></p>
                                        </td>
                                    </tr>
                                    </if>
                                </foreach>   
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="order-pro-total">
                	<div class="fl wctmes">
					
						<if condition="$userstate" >
                        <div class="syyouhui pa-to-15">
                        	<div class="duoxuk">
                            	 <label class="fo-fa-ta" for="order-chick">使用优惠券:</label>&nbsp;&nbsp;注：优惠券每次只能使用一张，不可多张混合使用
                       		</div>
                            <div class="byicd">
                            	<div class="zhiwfnka">
                                    	<table border="0" cellpadding="0" cellspacing="0">
                                            <tbody>
                                                <tr>
                                                    <td>
                                                    <input type="radio" class="radio vam ma-ri-10" name="couponTypeSelect" checked value="1"  onClick="ajax_order_price();" />
                                                     <select id="coupon_id" name="coupon_id" class="vam ou-no" onChange="ajax_order_price();">                                                     
                                                         <option value="0">选择优惠券</option>
					                                      <foreach name="couponList" item="v"  key="k">                                                     
                                                         	<option value="{$v['id']}">{$v['name']}</option>
                                                          </foreach>   
                                                     </select>
                                                    &nbsp;&nbsp;&nbsp;
                                                    <input type="radio" class="radio vam ma-ri-10" name="couponTypeSelect" value="2"  onClick="ajax_order_price();" />
                                                    <input type="text" name="couponCode" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入优惠券代码" /> 
                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onClick="ajax_order_price();" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>   
                                                    <label class="fo-fa-ta" for="order-chick">积分支付:</label>
                                                    <input type="text" id="pay_points" name="pay_points" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入使用积分"    onpaste="this.value=this.value.replace(/[^\d]/g,'')" onKeyUp="this.value=this.value.replace(/[^\d]/g,'')"/>
                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onClick="ajax_order_price();" />
                                                    <?php echo tpCache('shopping.point_rate');?> 积分抵 1元 &nbsp;&nbsp;   您的可用积分 {$user['pay_points']} 分
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>   
                                                    <label class="fo-fa-ta" for="order-chick">余额支付:</label>
                                                    <input type="text" id="user_money" name="user_money" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入使用余额"   onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onClick="ajax_order_price();" />
                                                    您的可用余额 ¥ {$user['user_money']}
                                                    </td>
                                                </tr>                                                
                                            </tbody>
                                        </table>
                                </div>
                            </div>
                        </div>   
						</if>                     
                    </div>
                    <div class="fr wcnhy">
                    	<div class="fzoubddv">
                        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <td class="tal">商品总金额：</td>
                                        <td class="tar">&nbsp;¥&nbsp;
                                           <em id="order-cost-area">{$total_price.total_fee}</em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">运费：</td>
                                        <td class="tar">&nbsp;¥&nbsp;
                                               <em id="postFee">0.00</em> 
                                        </td>
                                    </tr>
									<if condition="$userstate" >
                                    <tr>
                                        <td class="tal">使用优惠券：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="couponFee">0.00</span> </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">使用积分：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="pointsFee">0.00</span> </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">优惠活动：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="order_prom_amount">0.00</span> </em>
                                        </td>
                                    </tr>                                    
                                    <tr>
                                        <td class="tal">使用余额:</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="balance">0.00</span> </em>
                                        </td>
                                    </tr>  
									</if>                                  
                                </tbody>
                            </table>
                            <p class="yifje-order">
                            	<span class="p-subtotal-price"> 应付金额：
                                    <b class="total">¥</b>
                                    <b class="total" id="payables">0.00</b>
                                </span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="order-action-area te-al-ri">
            	<div class="woypdbe sc-acti-list pa-to-20">
                	<!--<span class="p-subtotal-price">应付总额：<b>¥<span class="vab" id="payableTotal">2276.00</span></b></span>-->
                    <a class="Sub-orders gwc-qjs" href="javascript:void(0);" onClick="submit_order();"><span>提交订单</span></a>
                </div>
            </div>
        </div>
    </div>
</form>    
<!--------footer-开始-------------->
<include file="Public/footer" />
<!--------footer-结束-------------->    
<script>
$(document).ready(function(){
	ajax_address(); // 获取用户收货地址列表
});
 
 

/**
* 新增修改收货地址
* id 为零 则为新增, 否则是修改
*  使用 公共的 layer 弹窗插件  参考官方手册 http://layer.layui.com/
*/
function add_edit_address(id)
{
	if(id > 0) 
		<if condition="!$userstate" >
		var url = "/index.php?m=Home&c=Address&a=edit_address&scene=1&call_back=call_back_fun&id="+id; // 修改地址
		<else />
		var url = "/index.php?m=Home&c=User&a=edit_address&scene=1&call_back=call_back_fun&id="+id; // 修改地址
		</if>
	else
		<if condition="!$userstate" >
		var url = "/index.php?m=Home&c=Address&a=add_address&scene=1&call_back=call_back_fun";	// 新增地址
		<else />
		var url = "/index.php?m=Home&c=User&a=add_address&scene=1&call_back=call_back_fun";	// 新增地址
		</if>
	layer.open({
		type: 2,
		title: '添加收货地址',
		shadeClose: true,
		shade: 0.8,
		area: ['880px', '580px'],
		content: url,
	}); 	
} 
// 添加修改收货地址回调函数 
function call_back_fun(v){	 
	layer.closeAll(); // 关闭窗口
	ajax_address(); // 刷新收货地址	
}

// 删除收货地址
function del_address(id)
{
    if(!confirm("确定要删除吗?"))
	  return false;
	  
	  $.ajax({
			<if condition="!$userstate" >
				url:"/index.php?m=Home&c=Address&a=del_address&id="+id,
			<else />
				url:"/index.php?m=Home&c=User&a=del_address&id="+id,
			</if>
  			 success: function(data){
				ajax_address(); // 刷新收货地址
                $('#ajax_pickup .order-address-list').removeClass('address_current');
             }
		  });	  	  
}
 
/*
* ajax 获取当前用户的收货地址列表
*/
function ajax_address(){
	$.ajax({
		url:"{:U('Home/Cart/ajaxAddress')}",//+tab,
		success: function(data){
			$("#ajax_address").html('');
			$("#ajax_address").append(data);
			if(data != '') // 有收货地址列表 再计算价钱
				ajax_order_price(); // 计算订单价钱
		}
	});
}


 
// 切换收货地址
function swidth_address(obj)
{
    var province_id = $(obj).attr('data-province-id');
    var city_id = $(obj).attr('data-city-id');
    var district_id = $(obj).attr('data-district-id');
    if (typeof($(obj).attr('data-province-id')) != 'undefined') {
        ajax_pickup(province_id,city_id,district_id,0);
    }
    $(".order-address-list").removeClass('address_current');
    $(obj).parent().parent().parent().parent().parent().addClass('address_current');
    if($('#address_id').length > 0)
        ajax_order_price(); // 计算订单价格
}

/**
 * 获取用户自提点和推荐自提点
 * @param type 1：用户自提点 ，0：用户自提点和推荐自提点
 * @param province_id 省
 * @param city_id 市
 * @param district_id 区
 */
function ajax_pickup(province_id, city_id, district_id,show) {
    $.ajax({
        type: 'GET',
        url: "{:U('Home/Cart/ajaxPickup')}",//+tab,
        data: {province_id: province_id, city_id: city_id, district_id: district_id,show:show},
        success: function (data) {
            $("#ajax_pickup").html('');
            $("#ajax_pickup").append(data);
        }
    });
}
//更换自提点
function replace_pickup(province_id, city_id, district_id) {
    var url = "/index.php?m=Home&c=Cart&a=replace_pickup&call_back=call_back_pickup&province_id="+province_id+"&city_id="+city_id+"&district_id="+district_id;
    layer.open({
        type: 2,
        title: '添加收货地址',
        shadeClose: true,
        shade: 0.8,
        area: ['880px', '580px'],
        content: url,
    });
}
// 添加自提点地址回调函数
function call_back_pickup(province_id,city_id,district_id){
    layer.closeAll(); // 关闭窗口
    ajax_pickup(province_id, city_id, district_id,1);
}


// 获取订单价格
function ajax_order_price()
{
	$.ajax({
		type : "POST",
		url:"{:U('Home/Cart/cart3')}",//+tab,
		data : $('#cart2_form').serialize()+"&act=order_price",// 你的formid
        dataType: "json",
		success: function(data){
			
			if(data.status != 1)
			{
				// alert(data.msg); //执行有误
				layer.alert(data.msg, {icon: 2});
				
				// 登录超时
				if(data.status == -100) 
					location.href ="{:U('Home/User/login')}";
								
				return false;
			}
			// console.log(data);		
			//$("#couponFee, #pointsFee, #order_prom_amount").css('display','none');

			$("#postFee").text(data.result.postFee); // 物流费
			$("#couponFee").text(data.result.couponFee);// 优惠券			
			$("#balance").text(data.result.balance);// 余额	
			$("#pointsFee").text(data.result.pointsFee);// 积分支付			
			$("#payables").text(data.result.payables);// 应付				
			$("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动 			
		}
	});	
}

// 提交订单
ajax_return_status = 1;
function submit_order()
{
	if(ajax_return_status == 0)
	    return false;
		
	ajax_return_status = 0;	
		
	$.ajax({
		type : "POST",
		url:"{:U('Home/Cart/cart3')}",//+tab,
		data : $('#cart2_form').serialize()+"&act=submit_order",// 你的formid
        dataType: "json",
		success: function(data){
												
			if(data.status != '1')
			{
				// alert(data.msg); //执行有误
				layer.alert(data.msg, {icon: 2});
				// 登录超时
				if(data.status == -100) 
					location.href ="{:U('Home/User/login')}";
				
				ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请求
				
				return false;
			}
			//alert();
			// console.log(data);		
			$("#postFee").text(data.result.postFee); // 物流费
			$("#couponFee").text(data.result.couponFee);// 优惠券			
			$("#balance").text(data.result.balance);// 余额	
			$("#pointsFee").text(data.result.pointsFee);// 积分支付			
			$("#payables").text(data.result.payables);// 应付	
			$("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动 									

			layer.msg('订单提交成功，跳转支付页面!', {
			  icon: 1,   // 成功图标
			  time: 2000 //2秒关闭（如果不配置，默认是3秒）
			}, function(){ // 关闭后执行的函数
					location.href = "/index.php?m=Home&c=Cart&a=cart4&order_id="+data.result; // 跳转到结算页
			});			
		}
	});	
}
</script>
</body>
</html>
